import logging
import datetime
import os
from common.tools import Tools

root_dir = Tools().get_rootdir()
logfile_dir = root_dir + '/logs/'
print(logfile_dir, '1111111111111')

today = datetime.datetime.today().strftime('%Y_%m_%d')
logfile = str(today) + '.log'
for root, dirs, files in os.walk(logfile_dir, topdown=False):
    if logfile not in files:
        # os.('../logs/' + logfile)
        with open(logfile_dir + logfile, 'w') as f:
            pass


def get_logger(name):
    logger = logging.getLogger(name)

    if not logger.handlers:
        logging.basicConfig(
            level=logging.INFO,
            filename=logfile_dir + logfile,
            filemode='a',
            format='[%(asctime)s][%(levelname)s]<%(name)s> %(message)s',
            datefmt='%I:%M:%S')
        handler = logging.FileHandler(logfile_dir + logfile)
        handler.setLevel(logging.INFO)
        # console = logging.StreamHandler()
        # console.setLevel(logging.INFO)
        formatter = logging.Formatter(
            fmt='[%(asctime)s][%(levelname)s]<%(name)s> %(message)s',
            datefmt='%I:%M:%S'
        )
        handler.setFormatter(formatter)
        logger.addHandler(handler)
        # logger.addHandler(console)
        logger.removeHandler(handler)
    return logger


if __name__ == '__main__':
    logger = get_logger('test')
    logger.info('1234')
